package com.zbkj.service.service.impl;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryV3Result;
import com.zbkj.dal.base.constants.*;
import com.zbkj.dal.base.enums.*;
import com.zbkj.dal.common.exception.CrmebException;
import com.zbkj.dal.common.utils.*;
import com.zbkj.dal.entity.fund.UserFundAccount;
import com.zbkj.dal.entity.order.DuesOrder;
import com.zbkj.dal.entity.order.UserDuesRecord;
import com.zbkj.dal.entity.user.User;
import com.zbkj.dal.entity.user.UserToken;
import com.zbkj.dal.entity.wechat.WechatPayInfo;
import com.zbkj.dal.pojo.request.PaySheOrderRequest;
import com.zbkj.dal.pojo.response.OrderPayResultResponse;
import com.zbkj.dal.pojo.vo.*;
import com.zbkj.service.manager.FundManager;
import com.zbkj.service.manager.QuotaManager;
import com.zbkj.service.model.dto.SaveUserBalanceRecordDTO;
import com.zbkj.service.service.*;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.support.TransactionTemplate;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

@Service
@Slf4j
public class DuesPayServiceImpl implements DuesPayService {
    @Autowired
    private UserService userService;
    @Autowired
    private DuesOrderService duesOrderService;
    @Autowired
    private AliPayService aliPayService;
    @Autowired
    private TransactionTemplate transactionTemplate;
    @Autowired
    private UserTokenService userTokenService;
    @Autowired
    private SystemConfigService systemConfigService;
    @Autowired
    private WechatService wechatService;
    @Autowired
    private UserDuesRecordService userDuesRecordService;
    @Autowired
    private WechatPayInfoService wechatPayInfoService;
    @Resource
    private FundManager fundManager;
    @Resource
    private QuotaManager quotaManager;

    @Resource
    private RedisTemplate<String, String> redisTemplate;

    @Value("${image.default.quota.recharge}")
    private String defaultQuotaRechargeImage;

    @Override
    public OrderPayResultResponse payment(PaySheOrderRequest paySheOrderRequest) {
        log.info("订单支付 START paySheOrderRequest:{}", JSON.toJSONString(paySheOrderRequest));
        DuesOrder order = duesOrderService.getByOrderNo(paySheOrderRequest.getOrderNo());
        log.info("订单支付 当前操作的订单信息:{}", JSON.toJSONString(order));
//        if (order.getCancelStatus() > OrderConstants.ORDER_CANCEL_STATUS_NORMAL) {
//            throw new CrmebException("订单已取消");
//        }
        if (Objects.equals(order.getPaid(), DuesStatusEnums.PAID.getCode())) {
            throw new CrmebException("订单已支付");
        }
//        if (order.getStatus() > OrderConstants.ORDER_STATUS_WAIT_PAY) {
//            throw new CrmebException("订单状态异常");
//        }
        User user = userService.getInfo();
        // 根据支付类型进行校验,更换支付类型
        order.setPayType(paySheOrderRequest.getPayType());
        order.setPayChannel(paySheOrderRequest.getPayChannel());
        // 余额支付
        if (paySheOrderRequest.getPayType().equals(PayConstants.PAY_TYPE_YUE)) {
            if (user.getNowMoney().compareTo(order.getPrice()) < 0) {
                throw new CrmebException("用户余额不足");
            }
        }

        OrderPayResultResponse response = new OrderPayResultResponse();
        response.setOrderNo(order.getOrderNo());
        response.setPayType(order.getPayType());
        response.setPayChannel(order.getPayChannel());
        if (order.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
            throw new CrmebException("支付金额不能低于等于0元");
        }
        // 余额支付
        if (order.getPayType().equals(PayConstants.PAY_TYPE_YUE)) {
            Boolean yueBoolean = yuePay(order, user);
            response.setStatus(yueBoolean);
            log.info("余额支付 response : {}", JSON.toJSONString(response));
            return response;
        }

        // 微信支付，调用微信预下单，返回拉起微信支付需要的信息
        if (order.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) {
            // 如果是微信支付缓存
            String key = String.format("dues-wx-pay-param-%s", order.getOrderNo());
            String voStr = redisTemplate.opsForValue().get(key);
            if (StringUtils.isNotBlank(voStr)) {
                OrderPayResultResponse cache = JSONUtil.toBean(voStr, OrderPayResultResponse.class);
                response.setStatus(true);
                response.setJsConfig(cache.getJsConfig());
                return response;
            }
            log.info("订单支付 微信下单");
            WxPayJsResultVo vo = wechatPayment(order);
            duesOrderService.updateById(order);
            response.setStatus(true);
            response.setJsConfig(vo);
            log.info("订单支付 微信下单 response :{}", JSON.toJSONString(response));
            redisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(vo), 15, TimeUnit.MINUTES);
            return response;
        }
        if (order.getPayType().equals(PayConstants.PAY_TYPE_ALI_PAY)) {
            log.info("订单支付 支付宝");
            String result = aliPayment(order);
            order.setOutTradeNo(order.getOrderNo());
            duesOrderService.updateById(order);
            response.setStatus(true);
            response.setAlipayRequest(result);
            log.info("订单支付 支付宝 response :{}", JSON.toJSONString(response));
            return response;
        }
        response.setStatus(false);
        log.info("订单支付 END response:{}", JSON.toJSONString(response));
        return response;
    }

    @Override
    public void duesOrderCancel(String orderNo) {
        DuesOrder order = duesOrderService.getByOrderNo(orderNo);
        if (Objects.isNull(order)) {
            throw new CrmebException("未查询到对应订单");
        }
        if (!Objects.equals(order.getPaid(), DuesStatusEnums.UNPAID.getCode())) {
            throw new CrmebException(String.format("订单状态：%s,不能取消", DuesStatusEnums.getCodeByDesc(order.getPaid())));
        }
        LambdaUpdateWrapper<DuesOrder> duesOrderLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        duesOrderLambdaUpdateWrapper.eq(DuesOrder::getId, order.getId())
                .set(DuesOrder::getPaid, DuesStatusEnums.CANCEL.getCode())
                .set(DuesOrder::getUpdateTime, LocalDateTime.now());
        duesOrderService.update(null, duesOrderLambdaUpdateWrapper);
    }

    @Override
    public Boolean queryWechatPayResult(String orderNo) {
        DuesOrder order = duesOrderService.getByOrderNo(orderNo);
        if (ObjectUtil.isNull(order)) {
            throw new CrmebException("订单不存在，orderNo=" + orderNo);
        }
//        if (order.getCancelStatus() > OrderConstants.ORDER_CANCEL_STATUS_NORMAL) {
//            throw new CrmebException("订单已取消");
//        }
        if (!order.getPayType().equals(PayConstants.PAY_TYPE_WE_CHAT)) {
            throw new CrmebException("不是微信支付类型订单");
        }
        if (Objects.equals(order.getPaid(), DuesStatusEnums.PAID.getCode())) {
            return Boolean.TRUE;
        }
        WechatPayInfo wechatPayInfo = wechatPayInfoService.getByNo(order.getOutTradeNo());
        if (ObjectUtil.isNull(wechatPayInfo)) {
            throw new CrmebException("未找到对应微信订单");
        }
//        WxPayOrderQueryResult wxPayOrderQueryResult = wechatService.payOrderQuery(order.getOutTradeNo());
//        wechatPayInfo.setIsSubscribe(wxPayOrderQueryResult.getIsSubscribe());
//        wechatPayInfo.setTradeState(wxPayOrderQueryResult.getTradeState());
//        wechatPayInfo.setBankType(wxPayOrderQueryResult.getBankType());
//        wechatPayInfo.setCashFee(wxPayOrderQueryResult.getCashFee());
//        wechatPayInfo.setCouponFee(wxPayOrderQueryResult.getCouponFee());
//        wechatPayInfo.setTransactionId(wxPayOrderQueryResult.getTransactionId());
//        wechatPayInfo.setTimeEnd(wxPayOrderQueryResult.getTimeEnd());
//        wechatPayInfo.setTradeStateDesc(wxPayOrderQueryResult.getTradeStateDesc());

        WxPayOrderQueryV3Result wxPayOrderQueryResult = wechatService.payOrderQueryV3(order.getOutTradeNo());
//        wechatPayInfo.setIsSubscribe(wxPayOrderQueryResult.getIsSubscribe());
//        wechatPayInfo.setTimeEnd(wxPayOrderQueryResult.getSceneInfo());
        wechatPayInfo.setTradeState(wxPayOrderQueryResult.getTradeState());
        wechatPayInfo.setBankType(wxPayOrderQueryResult.getBankType());
        WxPayOrderQueryV3Result.Amount amount = wxPayOrderQueryResult.getAmount();
        wechatPayInfo.setCashFee(amount.getPayerTotal());
        wechatPayInfo.setCouponFee(amount.getTotal() - amount.getPayerTotal());
        wechatPayInfo.setTransactionId(wxPayOrderQueryResult.getTransactionId());
        wechatPayInfo.setTradeStateDesc(wxPayOrderQueryResult.getTradeStateDesc());

        Boolean successAfter = duesOrderService.paySuccessAfter(order, wechatPayInfo);

        if (!successAfter) {
            throw new CrmebException("支付成功更新订单失败");
        } else {
            wechatPayInfoService.updateById(wechatPayInfo);
        }

        // 添加支付成功task
//        redisUtil.lPush(TaskConstants.ORDER_TASK_PAY_SUCCESS_AFTER, orderNo);
        return Boolean.TRUE;
    }

    /**
     * 支付宝支付
     *
     * @param order 订单
     * @return result
     */
    private String aliPayment(DuesOrder order) {
        return aliPayService.pay(order.getOrderNo(), order.getPrice(), "order", order.getPayChannel());
    }

    /**
     * 微信支付
     *
     * @param order 订单
     * @return WxPayJsResultVo
     */
    private WxPayJsResultVo wechatPayment(DuesOrder order) {
        // 预下单
        Map<String, String> unifiedorder = unifiedorder(order);
        WxPayJsResultVo vo = new WxPayJsResultVo();
        vo.setAppId(unifiedorder.get("appId"));
        vo.setNonceStr(unifiedorder.get("nonceStr"));
        vo.setPackages(unifiedorder.get("package"));
        vo.setSignType(unifiedorder.get("signType"));
        vo.setTimeStamp(unifiedorder.get("timeStamp"));
        vo.setPaySign(unifiedorder.get("paySign"));
        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_H5)) {
            vo.setMwebUrl(unifiedorder.get("mweb_url"));
        }
        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_APP_IOS) ||
                order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID)) {// App
            vo.setPartnerid(unifiedorder.get("partnerid"));
        }
        // 更新商户订单号
        order.setOutTradeNo(unifiedorder.get("outTradeNo"));
        return vo;
    }

    /**
     * 余额支付
     *
     * @param order 订单
     * @return Boolean Boolean
     */
    private Boolean yuePay(DuesOrder order, User user) {
        BigDecimal addPrice = order.getPrice();
        BigDecimal balance = user.getDuesAmount().add(addPrice);
        BigDecimal creditBalance = user.getCreditAmount().add(addPrice);

        user.setDuesAmount(balance);
        user.setCreditAmount(creditBalance);

        UserDuesRecord userDuesRecord = new UserDuesRecord();
        userDuesRecord.setUid(order.getUid());
        userDuesRecord.setLinkId(order.getOrderNo());
        userDuesRecord.setLinkType(BalanceRecordConstants.BALANCE_RECORD_LINK_TYPE_DUES);
        userDuesRecord.setType(BalanceRecordConstants.BALANCE_RECORD_TYPE_ADD);
        userDuesRecord.setAmount(addPrice);
        userDuesRecord.setBalance(balance);

        userDuesRecord.setCreditAmount(addPrice);
        userDuesRecord.setCreditBalance(creditBalance);

        userDuesRecord.setRemark(StrUtil.format(BalanceRecordConstants.BALANCE_RECORD_REMARK_RECHARGE, addPrice));

        // 用户余额扣除,添加承享额度
        Boolean execute = transactionTemplate.execute(e -> {
            Boolean update = Boolean.TRUE;
            // 订单修改
            order.setPaid(DuesStatusEnums.PAID.getCode());
            order.setPayTime(LocalDateTime.now());
//            order.setStatus(OrderConstants.ORDER_STATUS_WAIT_SHIPPING);
            duesOrderService.updateById(order);
            // 这里只扣除金额，账单记录在task中处理
            if (order.getPrice().compareTo(BigDecimal.ZERO) > 0) {
                // 查询用户雅识账户
                UserFundAccount userFundAccount = fundManager.minusAvailableAmount(user, order.getPrice(), FundAccountType.CRAB_ROE.name());
                SaveUserBalanceRecordDTO saveUserBalanceRecordDTO = SaveUserBalanceRecordDTO.builder()
                        .userFundAccount(userFundAccount).status(FundStatusEnums.FINISH.getCode()).image(FundTradeTypeEnums.QUOTA_RECHARGE.getDefaultImg())
                        .bizOrderNo(order.getOrderNo()).tradeAmount(order.getPrice()).fundType(FundTradeTypeEnums.QUOTA_RECHARGE.getCode())
                        .remark(String.format("订单：%s", order.getOrderNo())).fundDirection(FundDirectionEnums.OUTCOME.getCode()).build();
                fundManager.saveUserBalanceRecord(saveUserBalanceRecordDTO);
            }

            quotaManager.addQuota(user.getId(), order.getPrice(), order.getOrderNo(), QuotaChangeType.QUOTA_RECHARGE.getCode(), defaultQuotaRechargeImage, QuotaChangeType.QUOTA_RECHARGE.getDesc());
            //会费充值记录
            userDuesRecordService.save(userDuesRecord);
            return update;
        });
        if (!execute) throw new CrmebException("余额支付订单失败");

        return true;
    }

    /**
     * 预下单
     *
     * @param order 订单
     * @return 预下单返回对象
     */
    private Map<String, String> unifiedorder(DuesOrder order) {
        // 获取用户openId
        // 根据订单支付类型来判断获取公众号openId还是小程序openId
        UserToken userToken = new UserToken();
        userToken.setToken("");
        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_PUBLIC)) {// 公众号
            userToken = userTokenService.getTokenByUserId(order.getUid(), UserConstants.USER_TOKEN_TYPE_WECHAT);
        }
        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI)
                || order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_MINI_VIDEO)) {// 小程序
            userToken = userTokenService.getTokenByUserId(order.getUid(), UserConstants.USER_TOKEN_TYPE_ROUTINE);
        }

        // 获取appid、mch_id、微信签名key
        String appId = "";
        String mchId = "";
        String signKey = "";
        switch (order.getPayChannel()) {
            case PayConstants.PAY_CHANNEL_WECHAT_PUBLIC:
            case PayConstants.PAY_CHANNEL_H5:// H5使用公众号的信息
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PUBLIC_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_KEY);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_MINI:
            case PayConstants.PAY_CHANNEL_WECHAT_MINI_VIDEO:
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_MINI_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_KEY);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_APP_IOS:
            case PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID:
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_APP_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_KEY);
                break;
        }
        // 获取微信预下单对象
        CreateOrderRequestVo unifiedorderVo = getUnifiedorderVo(order, userToken.getToken(), appId, mchId, signKey);
        // 预下单（统一下单）
        CreateOrderResponseVo responseVo = wechatService.payUnifiedorder(unifiedorderVo);
        // 组装前端预下单参数
        Map<String, String> map = new HashMap<>();
        map.put("appId", unifiedorderVo.getAppid());
        map.put("nonceStr", responseVo.getNonceStr());
        map.put("package", "prepay_id=".concat(responseVo.getPrepayId()));
        map.put("signType", "RSA");
        Long currentTimestamp = WxPayUtil.getCurrentTimestamp();
        map.put("timeStamp", Long.toString(currentTimestamp));
//        String paySign = WxPayUtil.getSign(map, signKey);
        map.put("paySign", responseVo.getSign());
        map.put("prepayId", responseVo.getPrepayId());
        map.put("prepayTime", CrmebDateUtil.nowDateTimeStr());
        map.put("outTradeNo", unifiedorderVo.getOut_trade_no());
        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_H5)) {
            map.put("mweb_url", responseVo.getMWebUrl());
        }
        if (order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_APP_IOS) ||
                order.getPayChannel().equals(PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID)) {// App
            map.put("partnerid", mchId);
            map.put("package", responseVo.getPrepayId());
            Map<String, Object> appMap = new HashMap<>();
            appMap.put("appid", unifiedorderVo.getAppid());
            appMap.put("partnerid", mchId);
            appMap.put("prepayid", responseVo.getPrepayId());
            appMap.put("package", "Sign=WXPay");
            appMap.put("noncestr", unifiedorderVo.getAppid());
            appMap.put("timestamp", currentTimestamp);
            log.info("================================================app支付签名，map = " + appMap);
            String sign = WxPayUtil.getSignObject(appMap, signKey);
            log.info("================================================app支付签名，sign = " + sign);
            map.put("paySign", sign);
        }
        return map;
    }

    /**
     * 获取微信预下单对象
     *
     * @return 微信预下单对象
     */
    private CreateOrderRequestVo getUnifiedorderVo(DuesOrder order, String openid, String appId, String mchId, String signKey) {
        // 获取域名
        String domain = systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_SITE_URL);
        String apiDomain = systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_API_URL);

        AttachVo attachVo = new AttachVo(PayConstants.PAY_SERVICE_TYPE_DUES, order.getUid());

        CreateOrderRequestVo vo = new CreateOrderRequestVo();
        vo.setAppid(appId);
        vo.setMch_id(mchId);
        vo.setNonce_str(WxPayUtil.getNonceStr());
        vo.setSign_type(PayConstants.WX_PAY_SIGN_TYPE_MD5);
        String siteName = systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_SITE_NAME);
        // 因商品名称在微信侧超长更换为网站名称
        vo.setBody(siteName);
        vo.setAttach(JSONObject.toJSONString(attachVo));
        vo.setOut_trade_no(CrmebUtil.getOrderNo(OrderConstants.ORDER_PREFIX_WECHAT));
        // 订单中使用的是BigDecimal,这里要转为Integer类型
        vo.setTotal_fee(order.getPrice().multiply(BigDecimal.TEN).multiply(BigDecimal.TEN).intValue());
        //TODO 用于测试，上线前请注释
//        dto.setTotal_fee(1);
        vo.setSpbill_create_ip(RequestUtil.getClientIp());
        vo.setNotify_url(apiDomain + PayConstants.WX_PAY_NOTIFY_API_URI);
        switch (order.getPayChannel()) {
            case PayConstants.PAY_CHANNEL_H5:
                vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_H5);
                vo.setOpenid(null);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_APP_IOS:
            case PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID:
                vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_APP);
                vo.setOpenid(null);
                break;
            default:
                vo.setTrade_type(PayConstants.WX_PAY_TRADE_TYPE_JS);
                vo.setOpenid(openid);
        }
        CreateOrderH5SceneInfoVo createOrderH5SceneInfoVo = new CreateOrderH5SceneInfoVo(
                new CreateOrderH5SceneInfoDetailVo(
                        domain,
                        systemConfigService.getValueByKeyException(SysConfigConstants.CONFIG_KEY_SITE_NAME)
                )
        );
        vo.setScene_info(JSONObject.toJSONString(createOrderH5SceneInfoVo));
        String sign = WxPayUtil.getSign(vo, signKey);
        vo.setSign(sign);
        return vo;
    }

    private Map<String, String> getWechatQueryPayVo(String outTradeNo, String payChannel) {
        // 获取appid、mch_id
        // 微信签名key
        String appId = "";
        String mchId = "";
        String signKey = "";
        switch (payChannel) {
            case PayConstants.PAY_CHANNEL_WECHAT_PUBLIC:
            case PayConstants.PAY_CHANNEL_H5:// H5使用公众号的信息
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PUBLIC_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_PUBLIC_KEY);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_MINI:
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_MINI_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_MINI_KEY);
                break;
            case PayConstants.PAY_CHANNEL_WECHAT_APP_IOS:
            case PayConstants.PAY_CHANNEL_WECHAT_APP_ANDROID:
                appId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_APP_APPID);
                mchId = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_MCHID);
                signKey = systemConfigService.getValueByKeyException(WeChatConstants.WECHAT_PAY_APP_KEY);
                break;
        }

        // 生成查询订单对象
        Map<String, String> map = new HashMap<>();
        map.put("appid", appId);
        map.put("mch_id", mchId);
        map.put("out_trade_no", outTradeNo);
        map.put("nonce_str", WxPayUtil.getNonceStr());
        map.put("sign_type", PayConstants.WX_PAY_SIGN_TYPE_MD5);
        map.put("sign", WxPayUtil.getSign(map, signKey));
        return map;
    }
}
